﻿Imports PTIC_Util
Imports System.Data.OleDb
Imports System.Collections.ObjectModel

<Serializable()> Public Class GeneriqueTypedParametre_String
    Inherits GeneriqueTypedParametre(Of String)

    Public Sub New(ByVal nom As String, _
               ByVal description As String, _
               ByVal methodes_calcul As Boolean(), _
               ByVal initialValue As String)

        MyBase.New(nom, description, methodes_calcul, initialValue)
        'Initialisation de la table des valeurs
        Dim dtble_Valeurs As New DataTable
        dtble_Valeurs.Columns.Add(nom, GetType(String))
        Dim r As DataRow = dtble_Valeurs.NewRow()
        r(nom) = initialValue
        dtble_Valeurs.Rows.Add(r)
        _valeurs = dtble_Valeurs

        _ParamEtat = ParamEtat.Manual
        GeneriqueTypedParametre_Etat = New GeneriqueTypedParametre_EtatManuelString(Me)

    End Sub

    Public Overrides Property Etat As ParamEtat
        Get
            Return _ParamEtat
        End Get
        Set(ByVal value As ParamEtat)
            If value <> _ParamEtat Then
                _ParamEtat = value
                Select Case _ParamEtat
                    Case ParamEtat.Manual
                        GeneriqueTypedParametre_Etat = New GeneriqueTypedParametre_EtatManuelString(Me)
                    Case ParamEtat.Computed
                        GeneriqueTypedParametre_Etat = New GeneriqueTypedParametre_EtatComputed(Of String)(Me)
                End Select
            End If
        End Set
    End Property

    Public Overrides Sub Deserialize(ByVal param As IParametre)
        If param.Nom = Me.Nom And TypeOf param Is GeneriqueTypedParametre(Of String) Then
            Dim paramSave As GeneriqueTypedParametre(Of String) = DirectCast(param, GeneriqueTypedParametre(Of String))
            If paramSave.Nature = ParamNature.Unique Then
                Me.ValeurUnique = paramSave.ValeurUnique
            ElseIf param.Nature = ParamNature.Declinee Then
                GeneriqueTypedParametre_Etat.Deserialize(paramSave)
            End If
        End If
    End Sub

End Class
